package com.lanou.bookstore.order.web.servlet.admin;

import com.lanou.bookstore.order.dao.OrderDao;
import com.lanou.bookstore.order.dao.OrderDaoImpl;
import com.lanou.bookstore.order.domain.Order;
import com.lanou.bookstore.order.domain.Transit;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/adminoss")
public class AdminOrderStateServlet extends HttpServlet {

    OrderDao od = new OrderDaoImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String state = req.getParameter("state");
        String para = req.getParameter("para");
        String oid = req.getParameter("oid");

        List<Order> adminOrderList = null;

        if ("send".equals(para)) {
            od.changeOrderState(3, oid);
            adminOrderList = od.queryByState(3);

        }else {
            int i = Integer.parseInt(state);
            adminOrderList = od.queryByState(i);
        }


        List<Transit> adminOrderItemList = od.queryAll2();



        req.getSession().setAttribute("adminOrderList",adminOrderList);
        req.getSession().setAttribute("adminOrderItemList",adminOrderItemList);
        req.getRequestDispatcher("/adminjsps/admin/order/list02.jsp").forward(req,resp);
    }


}
